package cn.edu.sgu.www.mhxysy.controller.chongwu_equipment;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu_equipment.ChongwuWaiguanDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu_equipment.ChongwuWaiguanCategory;
import cn.edu.sgu.www.mhxysy.pager.chongwu_equipment.ChongwuWaiguanPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu_equipment.ChongwuWaiguanCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物外观管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_waiguan_category", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuWaiguanCategoryController {

	private final ChongwuWaiguanCategoryService chongwuWaiguanCategoryService;

	@Autowired
	public ChongwuWaiguanCategoryController(ChongwuWaiguanCategoryService chongwuWaiguanCategoryService) {
		this.chongwuWaiguanCategoryService = chongwuWaiguanCategoryService;
	}

	@ApiOperation("添加宠物外观")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated ChongwuWaiguanDTO chongwuWaiguanDTO) {
		chongwuWaiguanCategoryService.insert(chongwuWaiguanDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID修改宠物外观")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated ChongwuWaiguanDTO chongwuWaiguanDTO) {
		chongwuWaiguanCategoryService.updateById(chongwuWaiguanDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}
	
	@ApiOperation("查询全部宠物外观")
	@RequestMapping(value = "/selectAll", method = RequestMethod.GET)
	public JsonResult<List<ChongwuWaiguanCategory>> selectAll() {
		List<ChongwuWaiguanCategory> list = chongwuWaiguanCategoryService.selectAll();

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过ID查询宠物外观")
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<ChongwuWaiguanCategory> selectById(
			@ApiParam(name = "id", value = "宠物外观ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		ChongwuWaiguanCategory chongwuWaiguanCategory = chongwuWaiguanCategoryService.selectById(id);

		return JsonResult.success(null, chongwuWaiguanCategory);
	}

	@ApiOperation("查询id=1和id为当前id的宠物外观")
	@RequestMapping(value = "/selectList", method = RequestMethod.GET)
	public JsonResult<List<ChongwuWaiguanCategory>> selectList(
			@ApiParam(name = "id", value = "宠物外观ID", required = false)
			@RequestParam(required = false) Integer id) {
		List<ChongwuWaiguanCategory> list = chongwuWaiguanCategoryService.selectList(id);

		return JsonResult.success(null, list);
	}

	@ApiOperation("分页查询宠物外观列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<ChongwuWaiguanCategory>> selectByPage(ChongwuWaiguanPager pager) {
		Page<ChongwuWaiguanCategory> page = chongwuWaiguanCategoryService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}